﻿---@diagnostic disable: trailing-space
local extension = Package:new("moepack_token", Package.CardPack)
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack_token"] = "萌包衍生牌",
}

local U = require "packages/utility/utility"

--[[

  基本牌

]]--



--[[

  锦囊牌
  目录：单体，群体，延时

]]--



local kill_demon_skill = fk.CreateActiveSkill{
  name = "kill_demon_skill",
  target_num = 1,
  prompt = "#kill_demon_skill",
  can_use = function(self, player, card)
    local room = Fk:currentRoom()
    return card and table.find(room.alive_players, function (to)
      return not player:isProhibited(to, card) and (Fk.generals[to.general].name == "moe__mengnai" or (to.deputyGeneral ~= "" and Fk.generals[to.deputyGeneral].name == "moe__mengnai"))
    end)
  end,
  mod_target_filter = function(self, to_select)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return Fk.generals[to.general].name == "moe__mengnai" or to.deputyGeneral == "moe__mengnai"
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    room:damage({
      from = from,
      to = to,
      card = effect.card,
      damage = 1,
      skillName = self.name,
    })
    local cards = room:getSubcardsByRule(effect.card, { Card.DiscardPile })
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        toArea = Card.Void,
        moveReason = fk.ReasonJustMove,
        proposer = effect.from,
        skillName = self.name,
      })
    end
  end,
}
Fk:addSkill(kill_demon_skill)

local kill_demon = fk.CreateTrickCard{
  name = "&kill_demon",
  suit = Card.Spade,
  number = 1,
  skill = kill_demon_skill,
  special_skills = { "recast" },
}
extension:addCards({
  kill_demon,
  kill_demon:clone(Card.Spade, 3),
  kill_demon:clone(Card.Spade, 5),
  kill_demon:clone(Card.Spade, 7),
  kill_demon:clone(Card.Club, 2),
  kill_demon:clone(Card.Club, 4),
  kill_demon:clone(Card.Club, 6),
  kill_demon:clone(Card.Club, 8),
})
Fk:loadTranslationTable{
  ["kill_demon"] = "除魔",
  [":kill_demon"] = "锦囊牌（衍生牌）<br /><b>时机</b>：出牌阶段<br /><b>目标：</b>梦奈<br /><b>效果：</b>对目标角色造成1点伤害，然后将此牌移出游戏。",
  ["kill_demon_skill"] = "除魔",
  [":kill_demon_skill"] = "对梦奈造成1点伤害，然后将此牌移出游戏。",
  ["#kill_demon_skill"] = "对梦奈造成1点伤害，然后将此牌移出游戏",
}


local cent_coin_skill = fk.CreateActiveSkill{
  name = "cent_coin_skill",
  mod_target_filter = Util.TrueFunc,
  prompt = "#cent_coin_skill",
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    if target.dead then return end
    target:drawCards(1, "cent_coin")
  end
}
Fk:addSkill(cent_coin_skill)

local cent_coin = fk.CreateTrickCard{
  name = "&cent_coin",
  suit = Card.Spade,
  number = 1,
  skill = cent_coin_skill,
}
extension:addCards({
  cent_coin,
  cent_coin:clone(Card.Club, 1),
  cent_coin:clone(Card.Diamond, 1),
  cent_coin:clone(Card.Heart, 1),
})
Fk:loadTranslationTable{
  ["cent_coin"] = "幸运币",
  [":cent_coin"] = "锦囊牌（衍生牌）<br /><b>时机</b>：出牌阶段<br /><b>目标：</b>你<br /><b>效果：</b>目标角色摸一张牌",
  ["cent_coin_skill"] = "幸运币",
  [":cent_coin_skill"] = "摸一张牌",
  ["#cent_coin_skill"] = "摸一张牌",
}

--[[

  装备牌
  目录：武器，防具，坐骑，宝具

]]--



local nameless_sword_skill = fk.CreateViewAsSkill{
  name = "nameless_sword_skill",
  attached_equip = "nameless_sword",
  pattern = "slash",
  prompt = "#nameless_sword-prompt",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    local card = Fk:getCardById(to_select)
    return card and card.type == Card.TypeEquip and not(card.sub_type == Card.SubtypeWeapon and Fk:currentRoom():getCardArea(to_select) == Player.Equip)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("thunder__slash")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  enabled_at_response = function(self, player, response) return not response end, -- 只许使用不许打出
}

Fk:addSkill(nameless_sword_skill)

local nameless_sword = fk.CreateWeapon{
  name = "&nameless_sword",
  suit = Card.Club,
  number = 13,
  attack_range = 4,
  equip_skill = nameless_sword_skill,
}

extension:addCards({
  nameless_sword,
})

Fk:loadTranslationTable{
  ["nameless_sword"] = "无名刀",
  [":nameless_sword"] = "装备牌·武器（衍生牌）<br /><b>攻击范围</b>：4<br /><b>武器技能</b>：你可以将一张除装备区的武器牌以外的装备牌当雷【杀】使用。",
  ["nameless_sword_skill"] = "无名刀",
  [":nameless_sword_skill"] = "你可以将一张除装备区的武器牌以外的装备牌当雷【杀】使用。",
  ["#nameless_sword-prompt"] = "无名刀：你可以将一张除装备区的武器牌以外的装备牌当雷【杀】使用",
}




local mithril_dagger_skill = fk.CreateTriggerSkill{
  name = "#mithril_dagger_skill",
  anim_type = "offensive",
  attached_equip = "mithril_dagger",
  priority = 0.1,
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    local to = player.room:getPlayerById(data.to)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
    and (to.hp >= player.hp or to:getHandcardNum() >= player:getHandcardNum())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    if to.hp >= player.hp then
      data.disresponsiveList = data.disresponsiveList or {}
      table.insertIfNeed(data.disresponsiveList, data.to)
    end
    if to:getHandcardNum() >= player:getHandcardNum() then
      player:drawCards(1, self.name)
    end
  end,
}

Fk:addSkill(mithril_dagger_skill)

local mithril_dagger = fk.CreateWeapon{
  name = "&mithril_dagger",
  suit = Card.Heart,
  number = 3,
  attack_range = 2,
  equip_skill = mithril_dagger_skill,
}

extension:addCards({
  mithril_dagger,
})

Fk:loadTranslationTable{
  ["mithril_dagger"] = "秘银短匕",
  [":mithril_dagger"] = "装备牌·武器（衍生牌）<br /><b>攻击范围</b>：２<br /><b>武器技能</b>：锁定技，每当你使用【杀】指定目标后，若其体力值不小于你，其不可响应；若其手牌数不小于你，你摸一张牌。",
  ["#mithril_dagger_skill"] = "秘银短匕",
}

local assault_rifle_skill = fk.CreateTriggerSkill{
  name = "#assault_rifle_skill",
  anim_type = "offensive",
  attached_equip = "assault_rifle",
  priority = 0.1,
  events = {fk.TargetSpecified , fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TargetSpecified then
        local to = player.room:getPlayerById(data.to)
        return data.card.trueName == "slash" and not to.dead and to ~= player and #AimGroup:getAllTargets(data.tos) == 1
        and not player:isKongcheng() and player:getMark("@ARbullet") > 0
      else
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local to = player.room:getPlayerById(data.to)
      local ids = table.filter(player:getCardIds("h"), function (id)
        if Fk:getCardById(id).color ~= Card.Black then return false end
        local slash = Fk:cloneCard("slash")
        slash:addSubcard(id)
        slash.skillName = self.name
        return not player:prohibitUse(slash) and not player:isProhibited(to, slash)
      end)
      local card = room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = ids }), "#assault_rifle-slash:"..data.to)
      if #card > 0 then
        self.cost_data = card
        return true
      end
    else
      return true 
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      room:removePlayerMark(player, "@ARbullet")
      local to = room:getPlayerById(data.to)
      room:useVirtualCard("slash", self.cost_data, player, to, self.name, true)
    else
      room:addPlayerMark(player, "@ARbullet")
    end
  end,
}

Fk:addSkill(assault_rifle_skill)

local assault_rifle = fk.CreateWeapon{
  name = "&assault_rifle",
  suit = Card.Spade,
  number = 13,
  attack_range = 7,
  equip_skill = assault_rifle_skill,
  on_uninstall = function(self, room, player)
    Armor.onUninstall(self, room, player)
    room:setPlayerMark(player, "@ARbullet", 0)
  end,
}

extension:addCards({
  assault_rifle,
})



Fk:loadTranslationTable{
  ["assault_rifle"] = "突击步枪",
  [":assault_rifle"] = "装备牌·武器（衍生牌）<br /><b>攻击范围</b>：7<br /><b>武器技能</b>：你使用【杀】指定唯一目标后，你可以消耗1枚子弹，将一张黑色手牌当【杀】对其使用。你回合结束时获得1枚子弹，卸载武器时移除所有子弹。",
  ["#assault_rifle_skill"] = "突击步枪",
  ["@ARbullet"] = "子弹",
  ["#assault_rifle-slash"] = "突击步枪：可以消耗1枚子弹，将一张黑色手牌当【杀】对%src使用",
}

local kunwu_sword_skill = fk.CreateTriggerSkill{
  name = "#kunwu_sword_skill",
  anim_type = "offensive",
  events = {fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.from == player.id and data.card.trueName == "slash" and
      not player.room:getPlayerById(data.to).dead
  end,
  on_cost = function(self, event, target, player, data)
    self.cost_data = {tos = {data.to}}
    return player.room:askForSkillInvoke(player, self.name, nil, "#kunwu_sword-invoke::"..data.to)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, self.name)
    local to = room:getPlayerById(data.to)
    if not to.dead then
      room:loseHp(to, 1, self.name)
    end
    return true
  end,
}

Fk:addSkill(kunwu_sword_skill)

local kunwu_sword = fk.CreateWeapon{
  name = "&kunwu_sword",
  suit = Card.Spade,
  number = 2,
  attack_range = 3,
  equip_skill = kunwu_sword_skill,
}

extension:addCard(kunwu_sword)

Fk:loadTranslationTable{
  ["kunwu_sword"] = "锟铻剑",
  [":kunwu_sword"] = "装备牌·武器（衍生牌）<br /><b>攻击范围</b>：3<br /><b>武器技能</b>：每当你使用【杀】被目标抵消时，你可以与其各失去一点体力，令此【杀】仍然生效。",
  ["#kunwu_sword_skill"] = "锟铻剑",
  ["#kunwu_sword-invoke"] = "锟铻剑：你可以与 %dest 各失去1点体力，令其抵消的【杀】仍然生效",
}


local kingsbane_skill = fk.CreateTriggerSkill{
  name = "#kingsbane_skill",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(player:getCardIds("e")) do
      local card = Fk:getCardById(id)
      if card.name == "kingsbane" then
        room:setCardMark(card, "kingsbane_extra", card:getMark("kingsbane_extra") + 1)
      end
    end
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_refresh = function(self, event, target, player, data)
    for _, id in ipairs(player:getCardIds("e")) do
      local card = Fk:getCardById(id)
      if card.name == "kingsbane" then
        data.additionalDamage = (data.additionalDamage or 0) + card:getMark("kingsbane_extra")
      end
    end
  end,
}
Fk:addSkill(kingsbane_skill)

local kingsbane = fk.CreateWeapon{
  name = "&kingsbane",
  suit = Card.Spade,
  number = 1,
  attack_range = 1,
  dynamic_attack_range = function(self, player)
    return self:getMark("kingsbane_extra") + 1
  end,
  equip_skill = kingsbane_skill,
  ---@param room Room
  on_uninstall = function(self, room, player)
    Weapon.onUninstall(self, room, player)
    local cardId = self:getEffectiveId()
    if cardId and room:getCardArea(cardId) ~= Card.DrawPile then
      room:moveCards{
        from = room.owner_map[cardId],
        ids = {cardId},
        toArea = Card.DrawPile,
        drawPilePosition = math.random(#room.draw_pile + 1),
        moveReason = fk.ReasonJustMove,
        moveVisible = true,
      }
    end
  end,
}
extension:addCard(kingsbane)

Fk:loadTranslationTable{
  ["kingsbane"] = "弑君",
  [":kingsbane"] = "装备牌·武器（衍生牌）<br /><b>攻击范围</b>：1<br /><b>武器技能</b>：锁定技，每当你使用【杀】后，此武器的攻击范围+1，装备此武器时使用【杀】的伤害基数+1。此牌离开装备区后，保留以上效果并洗入牌堆。",
  ["#kingsbane_skill"] = "弑君",
}


local sun_parasol_skill = fk.CreateTriggerSkill{
  name = "#sun_parasol_skill",
  anim_type = "drawcard",
  attached_equip = "sun_parasol", 
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" 
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}

Fk:addSkill(sun_parasol_skill)

local sun_parasol = fk.CreateWeapon{
  name = "&sun_parasol",
  suit = Card.Diamond,
  number = 9,
  attack_range = 3,
  equip_skill = sun_parasol_skill,
}

extension:addCard(sun_parasol)

Fk:loadTranslationTable{
  ["sun_parasol"] = "晴伞",
  [":sun_parasol"] = "装备牌·武器（衍生牌）<br /><b>攻击范围</b>：3<br /><b>武器技能</b>：每当你使用【杀】时，你可以摸一张牌。",
  ["#sun_parasol_skill"] = "晴伞",
}



-- 防具



local rain_umbrella_skill = fk.CreateTriggerSkill{
  name = "#rain_umbrella_skill",
  anim_type = "drawcard",
  attached_equip = "rain_umbrella", 
  priority = 0.1, 
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" 
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}

Fk:addSkill(rain_umbrella_skill)

local rain_umbrella = fk.CreateArmor{
  name = "&rain_umbrella",
  suit = Card.Club,
  number = 6,
  equip_skill = rain_umbrella_skill,
}

extension:addCard(rain_umbrella)


Fk:loadTranslationTable{
  ["rain_umbrella"] = "雨伞",
	[":rain_umbrella"] = "装备牌·防具（衍生牌）<br /><b>防具技能</b>：每当你成为【杀】目标后，你可以摸一张牌。",
  ["#rain_umbrella_skill"] = "雨伞",
}



local whitefox_skill = fk.CreateTriggerSkill{
  name = "#whitefox_skill",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  attached_equip = "whitefox",
  events = {fk.EventPhaseStart},
  priority = 0.01,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/moepack/audio/card/whitefox")
    room:delay(500)
    
    room:useVirtualCard("analeptic", nil, player, player, self.name, false)
    if player.dead then return false end

    local to = player
    if player:hasSkill("emo__yuhu") then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player),Util.IdMapper), 1, 1, "#whitefox-damage", self.name, true)
      if #tos > 0 then
        to = room:getPlayerById(tos[1])
      end
    end

    room:damage { from = nil, to = to, damage = 1, skillName = "whitefox" }
    
  end,
}

Fk:addSkill(whitefox_skill)

local whitefox = fk.CreateTreasure{
  name = "&whitefox",
  suit = Card.Club,
  number = 10,
  equip_skill = whitefox_skill,
}

extension:addCard(whitefox)

Fk:loadTranslationTable{
  ["whitefox"] = "白狐",
  ["#whitefox_skill"] = "白狐",
  [":whitefox"] = "装备牌·宝物（衍生牌）<br/><b>宝物技能</b>：锁定技，出牌阶段开始时，你视为使用【酒】，然后受到1点伤害。",
  ["#whitefox-damage"] = "白狐：令一名其他角色受到1点无来源伤害",
}


local makima__peach = fk.CreateBasicCard{
  name = "&makima__peach",
  suit = Card.Heart,
  number = 6,
  skill = Fk:cloneCard("peach").skill,
} 

extension:addCards({
  makima__peach,
})


Fk:loadTranslationTable{
  ["makima__peach"] = "生姜炒肉",
	[":makima__peach"] = "基本牌（衍生牌）<br /><b>时机</b>：出牌阶段/一名角色处于濒死状态时<br /><b>目标</b>：已受伤的你/处于濒死状态的角色<br /><b>效果</b>：目标角色回复1点体力。",
}































--[[

Fk:loadTranslationTable{
  [""] = "",
  
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
}

--]]



return extension

